﻿function alter(field) {
    $.ajax({
        type:'POST',
        url: "demographicfield",
        data: { fieldID: field, pollID: $('#pollID').val() },
        success: function(html) {
            $('#values').html(html);
        }
    });
}
function changeType(type) {
    chartType = type;
    drawChart();
}

function drawChart() {
    var data = google.visualization.arrayToDataTable(dataArray);
    // Instantiate and draw our chart, passing in some options.
    var options = { width: 650, height: 400, title: 'Access Privileges Distribution',
        titleTextStyle: { fontSize: 20 },
        colors: ['Black', 'Blue']
    };

    if (chartType == "ColumnChart") {
        var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
        options['hAxis']= { title: dataArray[0][0] };
        options['vAxis'] = { title: dataArray[0][1] };;
    }
    else if (chartType == "BarChart") {
        var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
        options['vAxis']= { title: dataArray[0][0] };
        options['hAxis'] = { title: dataArray[0][1] };
    }
    else {
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
    }

    chart.draw(data, options);
}